package cn.kgc.javaweb.dao.impl;

import cn.kgc.javaweb.dao.RoleDao;
import cn.kgc.javaweb.entity.Role;
import cn.kgc.javaweb.utils.DruidUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * @author: mosin
 * @version: v1.0  2022/6/9
 */
public class RoleDaoImpl implements RoleDao {


    @Override
    public List<Role> selectAll() {

        QueryRunner queryRunner = new QueryRunner(DruidUtil.getDataSource());
        String sql ="select id ,role_name roleName from sys_role";
        try {
            List<Role> roles = queryRunner.query(sql, new BeanListHandler<Role>(Role.class));
            return  roles;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }
}
